<template>
  <el-rate
    v-model="current_field"
    :show-text="showTextValue"
    :show-score="showScoreValue"
    :disabled="disabledValue"
    :allow-half="current_args.half ? 'true' : 'false'"
    score-template="{value}"
    :max="$util.getDefValue(current_args.max, '5')"
  />
</template>
<script>
export default {
  props: {
    value: {
      type: String,
      default: ''
    },
    args: {
      type: Object,
      required: true,
      default: _ => {
        return {};
      }
    }
  },
  data() {
    return {
      current_field: this.value,
      current_args: this.args
    };
  },
  computed: {
    showTextValue() {
      if (this.current_args.show_text == '1') {
        return true;
      }

      return null;
    },
    showScoreValue() {
      if (this.current_args.show_score == '1') {
        return true;
      }

      return null;
    },
    disabledValue() {
      if (this.current_args.disabled == '1') {
        return true;
      }

      return null;
    }
  },
  watch: {
    current_field(value) {
      this.$emit('update:value', value);
    },
    value: {
      handler(now, old) {
        this.current_field = now;
      }
    }
  }
};
</script>
